package com.shangxia.spr.controller;

import com.shangxia.common.enums.MsgStateENUM;
import com.shangxia.common.vo.ResultVO;
import com.shangxia.spr.enums.attribute.BaseAttributeEnum;
import com.shangxia.spr.enums.attribute.PanelAttributeEnum;
import com.shangxia.spr.enums.attribute.QualificationEnum;
import com.shangxia.spr.enums.attribute.WarTimeAttributeEnum;
import com.shangxia.spr.enums.kungfu.KungFuQualityEnum;
import com.shangxia.spr.enums.kungfu.KungFuTypeEnum;
import com.shangxia.spr.enums.npc.BaseNpcEnum;
import com.shangxia.spr.enums.npc.NpcStateEnum;
import com.shangxia.spr.enums.npc.NpcTypeEnum;
import com.shangxia.spr.enums.state.SkillStateEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhouya38158
 * @date 2021/11/19 14:22
 * @apiNote 获取枚举字段
 */
@Slf4j
@RestController
@RequestMapping("/enum")
@Api("枚举")
public class EnumController {

    /**
     * 属性枚举
     */
    public static final Map<String, Object[]> ATTRIBUTE_ENUM_MAP = new HashMap<>();
    public static final Map<String, Object[]> ENUM_MAP = new HashMap<>();

    static {
        ATTRIBUTE_ENUM_MAP.put("BaseAttributeEnum", BaseAttributeEnum.values());
        ATTRIBUTE_ENUM_MAP.put("PanelAttributeEnum", PanelAttributeEnum.values());
        ATTRIBUTE_ENUM_MAP.put("QualificationEnum", QualificationEnum.values());
        ATTRIBUTE_ENUM_MAP.put("WarTimeAttributeEnum", WarTimeAttributeEnum.values());

        ENUM_MAP.put("KungFuQualityEnum", KungFuQualityEnum.values());
        ENUM_MAP.put("KungFuTypeEnum", KungFuTypeEnum.values());
        ENUM_MAP.put("BaseNpcEnum", BaseNpcEnum.values());
        ENUM_MAP.put("NpcStateEnum", NpcStateEnum.values());
        ENUM_MAP.put("NpcTypeEnum", NpcTypeEnum.values());
        ENUM_MAP.put("SkillStateEnum", SkillStateEnum.values());
    }


    @GetMapping("/attribute/list")
    @ApiOperation(notes = "属性枚举", value = "获取所有枚举")
    public ResultVO<List<String>> listAttributes() {
        return ResultVO.okResultVO(ATTRIBUTE_ENUM_MAP.keySet());
    }

    @GetMapping("/attribute/{enumName}")
    @ApiOperation(notes = "属性枚举", value = "获取属性枚举值")
    public ResultVO<List<String>> queryByAttributeEnumName(@PathVariable("enumName") String enumName) {
        if (ATTRIBUTE_ENUM_MAP.containsKey(enumName)) {
            return ResultVO.okResultVO(ATTRIBUTE_ENUM_MAP.get(enumName));
        } else {
            return ResultVO.errorResultVO(MsgStateENUM.PARAM_ERROR);
        }

    }


    @GetMapping("/{enumName}")
    @ApiOperation(notes = "枚举", value = "获取枚举值")
    public ResultVO<List<String>> queryByEnumName(@PathVariable("enumName") String enumName) {
        if (ENUM_MAP.containsKey(enumName)) {
            return ResultVO.okResultVO(ENUM_MAP.get(enumName));
        } else {
            return ResultVO.errorResultVO(MsgStateENUM.PARAM_ERROR);
        }
    }

}
